package com.cooper.scraper;

import com.cooper.android.comm.Resource;
import com.cooper.scraper.DownloadException;
import com.cooper.scraper.ResultUrl;
import com.cooper.scraper.ScraperException;

public class BrowseResourceCollector<T extends Resource> extends
		ResourceCollector<T> {

	private static final String BROWSE_LIST_KEY = "BROWSE_LIST_";

//	public BrowseResourceCollector(ResourceScraper<T> scraper) {
//		super(scraper);
//	}
	
	public BrowseResourceCollector(String scraperId){
		super(scraperId);
	}

	@Override
	public String generateKey() {
		return BROWSE_LIST_KEY + getPageNumber();
	}

	@Override
	public ResultUrl scraperListUrl() throws ScraperException,
			DownloadException {
		return scraper.createBrowseUrl(getPageNumber());
	}

	@Override
	public void scraperResult(String page, String referer) throws ScraperException,
			DownloadException {
		setMedias(scraper.extractBrowseResource(page, referer));
		setPageCount(scraper.getBrowsePageCount(page));
	}

	@Override
	public boolean subscribed(String key) {
		return key.startsWith(BROWSE_LIST_KEY);
	}

	@Override
	public void scraperResult(String page, String referer, String redirectUrl)
			throws ScraperException, DownloadException {
		setMedias(scraper.extractBrowseResource(page, referer, redirectUrl));
		setPageCount(scraper.getBrowsePageCount(page, redirectUrl));
	}

}
